package com.gxar.marketdelivery.domain.aviator.model;

import com.networknt.schema.Format;

import java.util.regex.Pattern;

/**
 * @author nice
 * @version 1.0
 * @created 2023/7/21.
 */
public class PatternWithMessageFormat implements Format {
    private final String name;
    private final Pattern pattern;
    private final String errorMessage;

    public PatternWithMessageFormat(String name, String regex, String errorMessage) {
        this.name = name;
        this.pattern = Pattern.compile(regex);
        this.errorMessage = errorMessage;
    }

    @Override
    public boolean matches(String value) {
        return pattern.matcher(value).matches();
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getErrorMessageDescription() {
        return errorMessage;
    }
}
